<?php

class admin_theme extends template
{
	public function __construct()
	{
		$this->north = true;		//顶部
		$this->west = true;			//左部
		$this->center = true;		//中部
		$this->east = false;		//无右部
		$this->south = true;		//底部
	}
	
	// head 头， 用于子类添加js和css
	protected function head(){}

	public function display()
	{
		$config = bone::get_config('system');
	?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?php echo $this->get_title().' - '.$config->site_name; ?></title>

<script type="text/javascript" language="javascript" src="../js/jquery-1.4.2.min.js"></script>

<link type="text/css" rel="stylesheet" href="css/global.css">
<script type="text/javascript" language="javascript" src="js/global.js"></script>

<link type="text/css" rel="stylesheet" href="themes/default/css/theme.css">
<script type="text/javascript" language="javascript" src="themes/default/js/theme.js"></script>

<?php $this->head();?>
</head>
<body>
<?php $this->body(); ?>
</body>
</html>
	<?php
	}
	
	protected function body()
	{
	?>
<div class="theme-north">
	<?php $this->north(); ?>
</div>

<div class="theme-middle">
	<?php $this->middle(); ?>
</div>
	<?php
	}
	
	protected function north()
	{
	?>
<a href="javascript:;" onclick="javascript:toggleWest();" title="打开/关闭左栏">
<img src="images/mini-logo.png" alt="Mr Bone V<?php echo bone::get_version(); ?>" border="0" />
</a>
<h2><?php echo $this->get('site_name');?></h2>
<div class="theme-north-menu">
	<ul>
		<li>
		<a href="index.php?controller=menu&task=listing">菜单管理</a>
		</li>
		<li>
		<a href="index.php?controller=themes&task=listing">主题管理</a>
		</li>
		<li>
		<a href="index.php?controller=application&task=listing">添加/删除应用</a>
		</li>
		<li>
		<a href="index.php?controller=config&task=config_system">系统配置</a>
		</li>
		<li class="logout">
		<a href="index.php?controller=user&task=logout">退出</a>
		</li>
	</ul>
</div>
	<?php
	}

	// 网页的中部
	protected function middle()
	{
	?>
<div class="theme-west">
	<?php $this->west(); ?>
</div>

<div class="theme-center">
	<?php $this->center(); ?>
</div>
	<?php
	}


	
	protected function west()
	{
	?>
<ul>
<?php
foreach($this->get('main_menu') as $menu)
{
	echo '<li><a href="'.$menu->url.'">'.$menu->name.'</a></li>';
}
?>
</ul>
	<?php
	}











	
	protected function message()
	{
		$message = $this->get('controller.message');
		if($message)
		{
			echo '<div class="message-'.$message->type.'">'.$message->body.'</div>';
		}
	}

	
	public function pagination()
	{
		$pagination = $this->get_pagination();
		
		$total = $pagination->get_total();
		$pages = $pagination->get_pages();
		$limit = $pagination->get_limit();
		$page = $pagination->get_page();
		$url = $pagination->get_url();

		echo '<div class="pagination">';
		if($page == 1)
		{
			echo '<span class="first">&lt;&lt;</span>';
			echo '<span class="pre">&lt;</span>';
		}
		else
		{
			echo '<span class="first"><a href="'.$url.'page=1">&lt;&lt;</a></span>';
			echo '<span class="pre"><a href="'.$url.'page='.($page-1).'">&lt;</a></span>';
		}

		echo '<span class="current">'.$page.'/'.$pages.'</span>';

		if($page < $pages)
		{
			echo '<span class="next"><a href="'.$url.'page='.($page+1).'">&gt;</a></span>';
			echo '<span class="last"><a href="'.$url.'page='.$pages.'">&gt;&gt;</a></span>';
		}
		else
		{
			echo '<span class="next">&gt;</span>';
			echo '<span class="last">&gt;&gt;</span>';
		}
		
		echo '<span class="goto">';
		echo '<select onchange="javascript:window.location.href=\''.$url.'page=\'+this.options[this.selectedIndex].value;">';
		for($i=1; $i<=$pages; $i++)
		{
			echo '<option value="'.$i.'"';
			if($i == $page) echo ' selected';
			echo '>'.$i.'</option>';
		}
		echo '</select>';
		echo '</span>';
		echo '</div>';
	}

	public function load_editor()
	{
	$this->editor = true;
	?>
<script type="text/javascript" src="../js/tiny_mce/jquery.tinymce.js"></script>
<script type="text/javascript">
	$().ready(function() {
		$('textarea.editor').tinymce({
			script_url : '../js/tiny_mce/tiny_mce.js',
			language : "zh",
			theme : "advanced",
			
			force_p_newlines : false, 
			force_br_newlines : true, 
			remove_linebreaks : false,
			button_tile_map : true,

			plugins : "media,paste,fullscreen",
			
			theme_advanced_buttons1 : "undo,redo,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,forecolor,backcolor,fontselect,fontsizeselect",
			theme_advanced_buttons2 : "paste,pastetext,pasteword,|,bullist,numlist,|,outdent,indent,|,hr,link,unlink,image,media,charmap,|,removeformat,code,fullscreen",
			theme_advanced_buttons3 : "",
			theme_advanced_buttons4 : "",
			theme_advanced_toolbar_location : "top",
			theme_advanced_toolbar_align : "left",
			theme_advanced_statusbar_location : "bottom",
			theme_advanced_resizing : true,
			theme_advanced_fonts : "黑体=黑体;楷体=楷体;仿宋=仿宋;隶书=隶书;幼圆=幼圆;Andale Mono=andale mono,times;Arial=arial,helvetica,sans-serif;Arial Black=arial black,avant garde;Book Antiqua=book antiqua,palatino;Comic Sans MS=comic sans ms,sans-serif;Courier New=courier new,courier;Georgia=georgia,palatino;Helvetica=helvetica;Impact=impact,chicago;Symbol=symbol;Tahoma=tahoma,arial,helvetica,sans-serif;Terminal=terminal,monaco;Times New Roman=times new roman,times;Trebuchet MS=trebuchet ms,geneva;Verdana=verdana,geneva;Webdings=webdings;Wingdings=wingdings,zapf dingbats",

			
			font_size_style_values : "8px,10px,12px,14px,18px,24px,36px",
			content_css : "css/content.css"
		});
	});
</script>
	<?php
	}	


	public function editor($editor_name, $value='', $width='100%', $height='200px')
	{
		if(!$this->editor) $this->load_editor();
		echo '<textarea name="'.$editor_name.'" id="'.$editor_name.'" class="editor" style="width:'.$width.';height:'.$height.';">'.htmlspecialchars($value).'</textarea>';
	}

}
?>